<template>
	<view>
		<view class="header">
			<!-- 轮播 -->
			<swiper
				class="swiper"
				indicator-color="rgba(255, 255, 255, 0.6)"
				indicator-active-color="rgba(255, 255, 255, 1)"
				@animationfinish="animationChange"
				:circular="true"
				:autoplay="true"
				:interval="3000"
				:duration="1000"
				:current="swiperCurrent"
			>
				<swiper-item @click="perviewImg(item, index)" v-for="(item, index) in swiperImg" :key="'img' + index">
					<image class="swiper-item" :src="item.image" mode=""></image>
				</swiper-item>
			</swiper>
			<!-- 轮播指示点样式修改 -->
			<!-- <view class="dots">
				<block v-for="(item, index) in swiperImg.length" :key="'dots'+index"><view class="dot" :class="index == swiperCurrent ? ' active' : ''"></view></block>
			</view> -->
		</view>
		<view class="container">
			<view class="tabs borderBottom10">
				<view v-for="(item, index) in tabs" :key="index">
					<view @click="selectTab(item, index)" :class="['inv-h', Inv == index ? 'inv-h-se' : '']">{{ item.name }}</view>
				</view>
			</view>
			<view class="list">
				<view class="list_content" @click="infoDetailHandle(item)" v-for="(item, index) in list" :key="'a' + index">
					<image :src="item.image" mode=""></image>
					<view class="right">
						<view class="right_title">{{ item.description }}</view>
						<view class="right_info">{{ item.title }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="loading">{{ loadingText }}</view>
	</view>
</template>

<script>
import { info } from '@/api/user/info/info.js';
import { wxSign } from '@/api/wxSign/wxSign.js';
export default {
	data() {
		return {
			swiperCurrent: 0, //轮播图下标
			Inv: 0, //选项卡
			loadingText: '加载中',
			swiperImg: [],
			tabs: [
				{
					name: '内容一'
				},
				{
					name: '内容二'
				},
				{
					name: '内容三'
				}
			],
			list: [],
			page:1,
			
		};
	},
	async onLoad() {
		let res = await info(1);
		this.swiperImg = res.data.adslist;
		this.getInfo(res)
		this.tabs = res.data.category;
		this.shareAll();
	},
	onReachBottom() {
		this.loadMore()
	},
	methods: {
		animationChange(e) {
			this.swiperCurrent = e.detail.current;
		},
		getInfo(res){
			if (res.data.artlist.data.length == 0) {
				this.loadingText = "没有数据了！";
			} else if (res.data.artlist.data.length < 10) {
				this.loadingText = "没有数据了！";
			} else {
				this.loadingText = "加载中";
			}
			if (this.page == 1) {
				this.list = res.data.artlist.data;
			} else {
				this.list = this.list.concat(res.data.artlist.data)
			}
		},
		async loadMore(){
			let res = await info(this.Inv,++this.page);
			this.getInfo(res)
		},
		async selectTab(item, index) {
			this.page=1
			uni.showLoading({
				title: '加载中'
			});
			let res = await info(item.id);
			this.getInfo(res)
			uni.hideLoading();
			this.Inv = index;
		},
		infoDetailHandle(item) {
			uni.navigateTo({
				url: '/pages/tabbar/info/infoDetail?id=' + item.id
			});
		},
		perviewImg(item, index) {
			// let urls = [];
			// this.swiperImg.forEach(item => {
			// 	urls.push(item.image);
			// });

			// uni.previewImage({sss
			// 	urls: urls,
			// 	current: urls[index],
			// 	indicator: 'number'
			// });
			if(item.url){
				window.location.href=item.url
			}
		},
		async shareAll() {
			let res = await wxSign();
			let local = 'http://qianhe.westts.cn/index.html';
			let shareContent = res.data.share;
			if ((res.code = 1)) {
				wx.config({
					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: res.data.wxaccessdata.appId, // 必填，公众号的唯一标识
					timestamp: res.data.wxaccessdata.timestamp, // 必填，生成签名的时间戳
					nonceStr: res.data.wxaccessdata.nonceStr, // 必填，生成签名的随机串
					signature: res.data.wxaccessdata.signature, // 必填，签名，见附录1
					jsApiList: [
						'onMenuShareAppMessage', //微信分享
						'onMenuShareTimeline', //微信分享
						'chooseWXPay', //微信支付
						'showOptionMenu',
						'updateAppMessageShareData',
						'hideMenuItems',
						'showMenuItems'
					]
				});
				wx.ready(function() {
					wx.onMenuShareAppMessage({
						title: shareContent.sharetitle, // 分享标题
						desc: shareContent.sharedesc,
						link: 'http://qianhe.westts.cn/index.html?id=' + res.data.share.shareid + '#/', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
						imgUrl: 'http://qianhe.westts.cn' + shareContent.shareimg, // 分享图标
						success: function() {}
					});
					wx.onMenuShareTimeline({
						title: shareContent.sharetitle, // 分享标题
						link: 'http://qianhe.westts.cn/index.html?id=' + res.data.share.shareid + '#/', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
						imgUrl: 'http://qianhe.westts.cn' + shareContent.shareimg, // 分享图标
						success: function() {
							// 用户点击了分享后执行的回调函数
						}
					});
				});
			}
		},
	}
};
</script>

<style lang="scss">
@import './css/info.scss';
</style>
